<template>
	<view class="content">
		<view class="match-top-box">
			<view class="match-title">尊敬的委托人：</view>
			<view class="match-txt">
				<view class="txt-down"></view>
				您好！法力平台正在为您匹配专业律师，请稍等片刻！我们将全心全意为您提供优质的服务！感谢您的信任与支持！
			</view>
			<view class="match-txt">
				<view class="txt-down">
					<uni-countdown
						:show-day="true"
						:day="remainTime.day"
						:hour="remainTime.hour"
						:minute="remainTime.minute"
						:second="remainTime.second"
						color="#f00"
						splitorColor="#f00"
						@timeup="timeup"
					></uni-countdown>
				</view>
				内，如未成功匹配律师的，法力平台将为您自动免费取消订单。
			</view>
			<view class="service-list">
				<button class="service-item active" style="width:250rpx; margin: auto;" @click="jump('/pages/client/user/to-cancel', { order_id: order_id,pay_type:info.order.pay_type  })">取消订单</button>
			</view>
		</view>
		<template v-if="info.order.price_type == '自费'">
			<!-- 待付信息 -->
			<order-wait-pay-info2 v-if="Object.keys(info.order).length > 0" :info="info" @init="init"   @clearTime="clearTime"></order-wait-pay-info2>
		</template>
		<template v-if="info.order.price_type != '自费'">
			<!-- 待付信息 -->
			<order-wait-pay-info v-if="Object.keys(info.order).length > 0" :info="info" @init="init"   @clearTime="clearTime"></order-wait-pay-info>
		</template>
		<!-- 付款详情 -->
		<order-common-detail v-if="Object.keys(info.order).length > 0" :detailLIst="info.order.pay_text" title="付款详情" :info="info"></order-common-detail>
		<!-- 案件主体信息 -->
		<order-case :info="info" :key="new Date().getTime() + 'case'" v-if="info.order.pro_name == '打官司'"></order-case>
		<!-- 订单详情  -->
		<order-detail ref="orderAllDetail" v-if="info.order.pro_name" :info="info.order"></order-detail>
		<!-- 超出48小时弹出层 -->
		<uni-popup ref="popupOut" type="dialog">
			<uni-popup-dialog type="info" title="" okTxt="确认" cancleTxt="" :content="outContent" :before-close="true" @confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
		<!-- 全局通用组件 -->
		<law-common ref="lawCommon"></law-common>
	</view>
</template>

<script>
import { mixin } from '@/common/mixins/match_order_state.js';
import { share_coupon } from '@/common/mixins/share_coupon.js';
export default {
	mixins: [mixin, share_coupon],
	data() {
		return {
			remainTime: {}, //剩余时间
			outContent: '超过48小时没有匹配到律师，感谢您的使用。',
			order_id: '',
			info: {
				order: {}
			}
		};
	},
	onLoad(params) {
		if (params.order_id) {
			this.order_id = params.order_id;
			this.init();
		}
	},
	onShow(){
		if(this.order_id){
			console.log("================this.info ,",this.order_id);
			this.init();
		}
	},
	methods: {
    clearTime(index){
      this.info.order.pend_text[index].isfinshed = false;
    },
		async init() {
			let formData = {
				id: this.order_id,
				token: uni.getStorageSync('token')
			};
			let res = await this.$api('index.orderDetail', formData);
			this.info = res.data;
      if(this.info.order.pend_text){
        this.info.order.pend_text.forEach((item)=>{
          if(item.chaotime){
            item.isfinshed = true;
            item.lvShiTime = this.timeFn(item.chaotime);
          }
        })
      }
			if(this.info.order.product_id != 6){
				this.$nextTick(() => {
					if (this.info.order.is_share) {
						this.$refs.orderAllDetail.$refs.popupShareConpon.open();
					}
				});
			}


			this.getOrderState(this.info);

			let d_time;
			if (this.info.order.change_time) {
				d_time = this.info.order.change_time;
			} else {
				d_time = this.info.order.createtime;
			}
			let d = this.getTwoDayLater(d_time);
      let times = this.timeFn(d)
      if(times.day=='2'){
        times.day = 0
        times.hour = 47
        times.minute = 59
        times.second = 59
      }
      this.remainTime = times;
      console.log("=======this.remainTime",this.remainTime,Object.values(this.remainTime))
		},
		dialogConfirm() {
			this.$refs.popupOut.close();
			this.replace('/pages/client/user/auto-cancel', {
				order_id: this.order_id,
        pay_type:this.info.order.pay_type
    });
		},
		timeup() {
			if (this.remainTime.day == '0'&&this.remainTime.hour == '0'&&this.remainTime.minute == '0'&&this.remainTime.second == '0') {
				this.$refs.popupOut.open();
			}
		}
	}
};
</script>

<style lang="scss">
.content {
	padding-bottom: 30rpx;
}
</style>
